package com.boco.action;

import java.util.ArrayList;
import java.util.List;

import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;

import com.boco.dao.GetEMR_MZJYJLData;
import com.boco.dao.SentData;
import com.boco.entity.EMR_MZJYJL;

public class InsertEMR_MZJYJLDataAction {
	private static final Log log = LogFactory.getLog(InsertEMR_MZJYJLDataAction.class);
	public  String insertData(){
		String url = "http://fasong.cdxp.csb/json/dzbl4";
		String resule = null;
		List<EMR_MZJYJL> list = new ArrayList<EMR_MZJYJL>();
		list = GetEMR_MZJYJLData.getData();
		
	    log.info("########################################");
	    log.info("数据总条数："+list.size());
	    log.info("########################################");
		String userName = "dzbl4";
		String password = "322dfbf9048445cabb06cbf24e64cdcf";
		EMR_MZJYJL temp = null;
		
		for(int i=0;i<list.size();i++){
			String param = null;
			temp = list.get(i);
			//log.info(temp.getXM());
			//按照身份证删除已经存在的值。
			param = "{\"SQL\":\"delete  EMR_MZJYJL where MJZH='"+
					temp.getMJZH()
					+"'"
					+ "\", \"ANNOTION\":\"cdxplogs\"}";
			resule = SentData.sendPost(url, param, userName, password);
			log.info("删除结果："+resule);
			param = "{\"SQL\":\"INSERT INTO EMR_MZJYJL ("
					+ "HZZSYH,"
					+ "YLJGZZJGDM,"
					+ "YLJGMC,"
					+ "MJZH,"
					+ "JXXMLSH,"
					+ "JYBGDBH,"
					+ "DZSQDBH,"
					+ "XM,"
					+ "HZLX,"
					+ "XB,"
					+ "NL,"
					+ "KSDM,"
					+ "KSMC,"
					+ "BQMC,"
					+ "BFH,"
					+ "BCH,"
					+ "JYSQJGDM,"
					+ "JYSQJG,"
					+ "JYSQKSDM,"
					+ "JYSQKS,"
					+ "JYBGJGDM,"
					+ "JYBGJG,"
					+ "JYBGKSDM,"
					+ "JYBGKS,"
					+ "JYBGJG2,"
					+ "JYBGBZ,"
					+ "JYBGRQ,"
					+ "ZDJGDM,"
					+ "ZDJGMC,"
					+ "ZDRQ,"
					+ "JBZDMC,"
					+ "JBZDDM,"
					+ "BGYSGH,"
					+ "BGYSQM,"
					+ "SHYSGH,"
					+ "SHYSQM,"
					+ "JYXMMC,"
					+ "ZRLSH,"
					+ "BCRQ,"
					+ "ORGCODE,"
					+ "AREACODE,"
					+ "UPLOADTIME,"
					+ "SOURCEID"
					+ ") VALUES("
					+ "'" + checkStr(temp.getHZZSYH()) + "'," 
					+ "'" + checkStr(temp.getYLJGZZJGDM()) + "'," 
					+ "'" + checkStr(temp.getYLJGMC()) + "'," 
					+ "'" + checkStr(temp.getMJZH()) + "'," 
					+ "'" + checkStr(temp.getJXXMLSH()) + "'," 
					+ "'" + checkStr(temp.getJYBGDBH()) + "'," 
					+ "'" + checkStr(temp.getDZSQDBH()) + "'," 
					+ "'" + checkStr(temp.getXM()) + "',"
					+ "'" + checkStr(temp.getHZLX()) + "'," 
					
					+ "'" + checkStr(temp.getXB()) + "'," 
					+ "" + checkStr(temp.getNL()) + ","
					+ "'" + checkStr(temp.getKSDM()) + "',"
					+ "'" + checkStr(temp.getKSMC()) + "'," 
					+ "'" + checkStr(temp.getBQMC()) + "'," 
					+ "'" + checkStr(temp.getBFH()) + "'," 
					+ "'" + checkStr(temp.getBCH()) + "'," 
					+ "'" + checkStr(temp.getJYSQJGDM()) + "'," 
					
					+ "'" + checkStr(temp.getJYSQJG()) + "'," 
					+ "'" + checkStr(temp.getJYSQKSDM()) + "',"
					+ "'" + checkStr(temp.getJYSQKS()) + "',"
					+ "'" + checkStr(temp.getJYBGJGDM()) + "'," 
					+ "'" + checkStr(temp.getJYBGJG()) + "'," 
					+ "'" + checkStr(temp.getJYBGKSDM()) + "'," 
					+ "'" + checkStr(temp.getJYBGKS()) + "'," 
					+ "'" + checkStr(temp.getJYBGJG2()) + "'," 
					+ "'" + checkStr(temp.getJYBGBZ()) + "'," 
					+ "to_date('" + checkStr(temp.getJYBGRQ()) + "','yyyy-MM-dd HH24:mi:ss')," 
					+ "'" + checkStr(temp.getZDJGDM()) + "'," 
					+ "'" + checkStr(temp.getZDJGMC()) + "'," 
					+ "to_date('" + checkStr(temp.getZDRQ()) + "','yyyy-MM-dd HH24:mi:ss')," 
					
					+ "'" + checkStr(temp.getJBZDMC()) + "',"
					+ "'" + checkStr(temp.getJBZDDM()) + "',"
					+ "'" + checkStr(temp.getBGYSGH()) + "'," 
					+ "'" + checkStr(temp.getBGYSQM()) + "'," 
					+ "'" + checkStr(temp.getSHYSGH()) + "'," 
					+ "'" + checkStr(temp.getSHYSQM()) + "'," 
					+ "'" + checkStr(temp.getJYXMMC()) + "'," 
					+ "'" + checkStr(temp.getZRLSH()) + "'," 
					+ "to_date('" + checkStr(temp.getBCRQ()) + "','yyyy-MM-dd HH24:mi:ss')," 
					+ "'" + checkStr(temp.getORGCODE()) + "'," 
					+ "'" + checkStr(temp.getAREACODE()) + "'," 
					+ "sysdate," 
					+ "'dzbl4'" 
					+ ")\", \"ANNOTION\":\"cdxplogs\"}";
					resule = SentData.sendPost(url, param, userName, password);
					log.info(resule);
					
		}
		log.info("上传完成！");
		return resule;
		
	
		
	}
	
	public static String checkStr(Object obj){
		if (obj== null){
			obj = "";
		}
		return (String) obj;
	}
	
	
}
